package com.activenetwork.util;

import java.io.File;

public class XMLBindingHelper {
	private File xml;
	

	@SuppressWarnings("unused")
	private XMLBindingHelper(){}
	
	/**
	 * Direct File Object constructor
	 * @param xmlFile
	 */
	public XMLBindingHelper(File xmlFile){
		xml = xmlFile;
	}
	/**
	 * Suppose the xml is under test case class folder with unknown name
	 * @param testCaseClazz
	 * @param fileName
	 */
	public XMLBindingHelper(Class<?> testCaseClazz, String xmlFileName){
		String xmlFilePath = testCaseClazz.getResource("").getPath();
        String xmlFileFullPath = xmlFilePath + xmlFileName + ".xml";
        xml = new File(xmlFileFullPath);
	}
	/**
	 * Suppose the xml is under test case class folder with same class short name
	 * @param testCaseClazz
	 * @return
	 */
	public XMLBindingHelper(Class<?> testCaseClazz){
		String xmlFilePath = testCaseClazz.getResource("").getPath();
		String xmlFileName = testCaseClazz.getSimpleName();
		String xmlFileFullPath = xmlFilePath + xmlFileName + ".xml";
		xml = new File(xmlFileFullPath);
	}
	/**
	 * Suppose xml file is located by user anywhere
	 * @param filePath
	 * @param fileName
	 */
	public XMLBindingHelper(String xmlFilePath, String xmlFileName){
		String xmlFileFullPath = xmlFilePath + xmlFileName + ".xml";
		xml = new File(xmlFileFullPath);
	}
	/**
	 * Suppose the xml file is under project src folder
	 * @param xmlFileName
	 */
	public XMLBindingHelper(String xmlFileName){
		String xmlFilePath = XMLBindingHelper.class.getClassLoader().getResource("").getPath();
		String xmlFileFullPath = xmlFilePath + xmlFileName + ".xml";
		xml = new File(xmlFileFullPath);
	}
	/**
	 * Binding the xml with schema object
	 * @param <T>
	 * @param xmlRootNodeType
	 * @return
	 */
	public <T extends Object> T binding(Class<T> xmlRootNodeType){
		String bindingClassPath = xmlRootNodeType.getPackage().getName();
		return JaxbUtil.buildObject(xml, bindingClassPath, xmlRootNodeType);
	}
	

	
}
